package vmcs.controller;

import vmcs.controller.MaintenanceController;
import vmcs.controller.SimulationController;
import vmcs.utility.Environment;
import vmcs.boundary.SimulatorControlPanel;
import vmcs.utility.VMCSException;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

public class MainController {
    private SimulationController    simulatorCtrl;
    private MaintenanceController   maintenanceCtrl;
    private StoreController         storeCtrl;
    private CustomerController      customerCtrl;
    //private TransactionController   transactionCtrl;
    public  Environment             env;

  public MainController() {
  }


  public void initialize()
  throws VMCSException {
    try {
        env = new Environment();
        env.initialize();
        simulatorCtrl = new SimulationController(this);
        storeCtrl = new StoreController(this);
        storeCtrl.initialize();
        maintenanceCtrl = new MaintenanceController(this);
        customerCtrl = new CustomerController(this, maintenanceCtrl);
        //transactionCtrl = new TransactionController();
        customerCtrl.setMaintenanceCtrl(maintenanceCtrl);
        customerCtrl.setSimulatorCtrl(simulatorCtrl);
        customerCtrl.setStoreCtrl(storeCtrl);
    }   catch (VMCSException e){
        throw new VMCSException ("MainController.initialize", e.getMessage());
    }
  }

  public void  start()
  throws VMCSException {
    try {
        initialize();
        simulatorCtrl.displaySimulatorControlPanel();
        simulatorCtrl.setSimulationActive(false);
    } catch (VMCSException e){
      throw new VMCSException (e);
    }
  }
  
  public CustomerController getCustomerController(){
      return customerCtrl;
  }

  public SimulationController  getSimulationController(){
    return simulatorCtrl;
  }

  public SimulatorControlPanel    getSimulatorControlPanel(){
    return simulatorCtrl.getSimulatorControlPanel();
  }

  public StoreController   getStoreController(){
    return storeCtrl;
  }

   public MaintenanceController   getMaintenanceController(){
    return maintenanceCtrl;
  }

  public void closeDown(){

    if (maintenanceCtrl.closeDown() == false)
      return;
    try {
        storeCtrl.closeDown();
    } catch (VMCSException e){
      System.out.println("MainController.closeDown"+ e);
    }
    simulatorCtrl.closeDown();
  }
}
